package com.foogui.primary.sync;

import java.util.stream.IntStream;

public class ThreadLocalDemo {
    private static ThreadLocal<User> local = new ThreadLocal<>();
    public static void main(String[] args) {

        IntStream.range(1,10).forEach(i->{
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"正在运行");
                local.set(new User(i+"号"));
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(local.get().getName());
            },i+"").start();

        });
    }
}
